<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>属性侦听</title>
    <script src="https://unpkg.com/vue@3/dist/vue.global.js"></script>
</head>
<body>
<div id="app">
    <!--    定义一个输入框    -->
    <input v-model="searchText"/>
</div>
</body>
<script>
    const App = Vue.createApp({
        data() {
            return {
                searchText: ""  // 绑定到输入框的属性
            }
        },
        watch: {
            // 监听searchText属性的变化
            searchText(newValue, oldValue) {
                // 当监听到输入的字符长度大于10时，弹出提示框
                if (newValue.length > 10) {
                    alert("输入的字符长度不能超过10")
                }
            }
        }
    })
</script>
</html>